#!/usr/bin/env python

from google.appengine.api import users

from gaeo.controller import Controller


class NotLoggedInError(Exception): pass
class NotAdminError(Exception): pass

class Admin(Controller):    
    def index(self):
        try:
            if self.view.member is None:
                raise NotLoggedInError()
            
            if not self.view.member.is_admin:
                raise NotAdminError()
            
        except NotLoggedInError:
            self.redirect(users.create_login_url(self.request.path), False)
        except NotAdminError:
            self.response.out.write('<h1>No Permission</h1><a href="/user/logout">Logout</a>')
            self.set_no_render()
            return
            
    def forum(self):
        from application.models import Forum
        
        forums = Forum.all()
        forums.order('created')
        
        self.view.forums = forums